package srpingmvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class HelloControllerTwo {

    @RequestMapping("/hellospringmvc")
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        //第一种方式index.jsp：用的是绝对真实路径
//        ModelAndView mav = new ModelAndView("/index.jsp");
        //第二种方式index：用的是相对路径
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("message", "Hello Spring MVC");
        return mav;
    }

    //    使用 Servlet 原生 API 实现
    @RequestMapping("/request")
    public ModelAndView getParam(HttpServletRequest request,
                                 HttpServletResponse response) {
        String userName = request.getParameter("userName");
        String password = request.getParameter("password");

        System.out.println("Spring MVC 传参方式");
        System.out.println(userName);
        System.out.println(password);
        return null;
    }

    @RequestMapping("/interceptor")
    public ModelAndView showInterceptor()  {
        ModelAndView mav = new ModelAndView("hellotwo");
        mav.addObject("message", "Hello Spring MVC");
        return mav;
    }

}
